package com.eber.demo.design.proxy;

// 接口
interface Subject {
    void request();
}

// 真实主题类
class RealSubject implements Subject {
    @Override
    public void request() {
        System.out.println("RealSubject processing request.");
    }
}

// 代理类
class Proxy implements Subject {
    private RealSubject realSubject;

    @Override
    public void request() {
        if (realSubject == null) {
            realSubject = new RealSubject();
        }
        preProcess();
        realSubject.request();
        postProcess();
    }

    private void preProcess() {
        System.out.println("Pre-processing before request.");
    }

    private void postProcess() {
        System.out.println("Post-processing after request.");
    }
}

public class ProxyApplication {
    public static void main(String[] args) {
        Subject proxy = new Proxy();
        proxy.request();
    }
}
